<!DOCTYPE html>
<html>
<head>
    <title>攻略系列</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyCatalogs.css"/>
    <link rel="stylesheet" href="js/plugins/pingjia/css/new_file.css">
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="js/common.js"></script>
<!--    <link rel="stylesheet" href="/js/plugins/comment/css/bootstrap.css">
    <script src="/js/plugins/comment/js/jquery.comment.js"></script>-->

    <script>
        $(function () {

            //获取当前登录用户信息
            var userStr = sessionStorage.getItem("user");
            var userJSON;


            //检查登录状态
            function checkLogin() {
                if (userStr == null) {
                    $(document).dialog({
                        type: 'confirm',
                        style: 'IOS',
                        titleShow: false,
                        content: '登录后才能收藏和点赞哟~',
                        buttons: [
                            {
                                name: '取消',
                                callback: function () {
                                }
                            },
                            {
                                name: '确定',
                                callback: function () {
                                    window.parent.location.href = "/login.html";
                                }
                            }
                        ]
                    });
                    return;
                }

            }

            //大攻略参数
            var params = getParams();
            //发送Ajax请求查询攻略的点赞和收藏数
            $.get("/strategyConcerns/" + params.id, function (data) {
                $("#likerNums").html(data.likerNums);
                $("#collectorNums").html(data.collectorNums);
            });


            //给评论动态绑定点击事件
            $("#comment").on("click",".commentBtn",function () {
                var commentId = $(this).attr("content");
                window.location.href="/mine/strategyComment.html?id="+ commentId;
            });

            //给点赞动态绑定点击事件
            $("#comment").on("click",".likeBtn",function () {
                var commentId = $(this).attr("content");
                checkLogin();
                userJSON = JSON.parse(userStr);
                $.get("/strategies/strategyCommentLikers/"+commentId+"/"+userJSON.id,function (data) {
                    $(this).find('span').html(data);
                });
            });

            //点评按钮
            $("#commentBtn").click(function () {
                if (params.id) {
                    window.parent.location.href = "/mine/addComment.html?id="+params.id;
                }
            });



            //回显该攻略的所有标签和评论信息
            if (params.id) {
                $.get("/strategies/"+params.id+"/tags",{pageSize:0},function (data) {
                    $(".tag").renderValues(data);
                });
                $.get("/strategies/"+params.id+"/strategyComments",{pageSize:0},function (data) {
                    $("#comment").renderValues(data,{
                        setHref:function (ele,val) {
                            var href = $(ele).attr("href")+val;
                            $(ele).attr("href",href);
                        },
                        setValue:function (ele,val) {
                            $(ele).attr("content",val);
                        },
                        setStar:function (ele, val) {
                            var html ="";
                            if(val == 1){
                                html =  '<i class="fa fa-star"></i><i class="fa fa-star-o"></i><i class="fa fa-star-o"></i>' +
                                    '<i class="fa fa-star-o"></i><i class="fa fa-star-o"></i>';
                            }else if (val ==2){
                                html =  '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star-o"></i>' +
                                    '<i class="fa fa-star-o"></i><i class="fa fa-star-o"></i>';
                            }else if (val ==3){
                                html =  '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i>' +
                                    '<i class="fa fa-star-o"></i><i class="fa fa-star-o"></i>';
                            }else if (val ==4){
                                html =  '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i>' +
                                    '<i class="fa fa-star"></i><i class="fa fa-star-o"></i>';
                            }else if (val ==5){
                                html =  '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i>' +
                                    '<i class="fa fa-star"></i><i class="fa fa-star"></i>';
                            }else {
                                html =  '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i>' +
                                    '<i class="fa fa-star-o"></i><i class="fa fa-star-o"></i>';

                            }
                            $(ele).html(html);
                        }
                    });
                });
            }

                //点赞的同时更新点赞数
                $("#like").click(function () {
                    checkLogin();
                    userJSON = JSON.parse(userStr);
                    $.post("/strategyConcerns/newLikerNums/" + params.id + "/" + userJSON.id, function (data) {
                        $("#likerNums").html(data);
                    });
                });
                //收藏的同时更新收藏数
                $("#collect").click(function () {
                    checkLogin();
                    userJSON = JSON.parse(userStr);
                    $.post("/strategyConcerns/newCollectorNums/" + params.id + "/" + userJSON.id, function (data) {
                        $("#collectorNums").html(data);
                    });
                });



            //大攻略信息明细
            if (params.id) {
                $.get("/strategies/" + params.id, function (data) {
                    $(".strategies").renderValues(data);


                    //大攻略下的全部目录
                    $.get("/strategies/" + params.id + "/catalog", function (data) {
                        var sum = 0;
                        $(".catalogs").renderValues({"list": data}, {
                            setName: function (ele, val) {
                                $(ele).html((sum++) + val);
                            },
                            setHref: function (ele, val) {
                                $(ele).attr("href", $(ele).attr("href") + val);
                            }
                        });
                    })
                })
            }

            //大家都在看
            if(params.id){
                $.get("/strategyTravels?strategyId="+params.id,function (data) {
                    $(".hot").renderValues({list:data},{
                        setHref:function (ele,val) {
                            $(ele).attr("href",$(ele).attr("href")+val);
                        }
                    })

                })
            }
        })
    </script>

</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜索旅行攻略">
            </div>
        </div>
    </div>
</div>


<div class="container strategies">
    <h5 class="title" render-html="title"></h5>
    <small><span>0</span>人阅读过此攻略</small>
    <div class="focus">
        <i class="fa fa-heart" id="collect"><span id="collectorNums"> 0</span> 收藏</i>
        <i class="fa fa-thumbs-up" id="like"><span id="likerNums"> 0</span> 点赞</i>

        <button class="btn">想去</button>
        <button class="btn">去过</button>
    </div>
</div>

<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab">
    <li class="nav-item ">
        <a class="nav-link active" id="pills-catalog-tab" data-toggle="pill" href="#pills-catalog">
            <span>攻略目录</span>
        </a>
    </li>
    <li class="nav-item">
        <a class="nav-link " id="pills-comment-tab" data-toggle="pill" href="#pills-comment">
            <span>骡友点评</span>
        </a>
    </li>
</ul>
<div class="tab-content " id="pills-tabContent">
    <div class="tab-pane fade show active" id="pills-catalog">
        <div class="container hot">
            <h6>大家都在看</h6>
            <div render-loop="list">
                <a href="/travelContent.html?id=" render-fun="setHref" render-key="list.id">
                    <button class="btn" render-html="list.title">上下九</button>
                </a>
            </div>
        </div>

        <!--大攻略下的概况-->
        <div class="catalogs">
            <div render-loop="list">
                <div class="container detail">
                    <h6 render-fun="setName" render-key="list.name"></h6>
                    <div render-loop="list.details">
                        <a href="strategyDetails.html?id=" render-fun="setHref" render-key="list.details.id">
                            <button class="btn" render-html="list.details.title"></button>
                        </a>
                    </div>
                </div>
            </div>
        </div>

    </div>

    <div class="tab-pane fade " id="pills-comment">

        <div class="container tag">
            <h6>骡友标签</h6>
            <div render-loop="list">
                <span render-value="list.tagId" render-html="list.tagName"></span>
            </div>
        </div>
        <hr>

        <div id="comment">
            <div render-loop="list">


                <div class="container row comment">
                    <div class="col-2 comment-head">
                        <a href="/mine/userProfiles.html?id=" render-fun="setHref" render-key="list.commentator.id">
                            <img class="rounded-circle" render-src="list.commentator.headImgUrl">
                        </a>
                    </div>
                    <div class="col comment-right">
                        <p class="authorName"><span render-html="list.commentator.nickName"></span>
                        </p>

                        <span class="comment-star" render-fun="setStar" render-key="list.star"> </span>
                        <span class="comment-date" render-html="list.date"></span>
                        <div class="comment-content">
                            <a href="/mine/strategyComment.html">
                                <p render-html="list.content"></p>
                            </a>
                        </div>
<!--


                        <ul class="comment-img">
                            <li>
                                <img render-src="list.commentator.headImgUrl">
                            </li>
                        </ul>
-->


                        <div class="d-flex icon">
                            <a data-href="/mine/strategyComment.html">
                                <i class="fa  fa-commenting-o commentBtn" style="margin-right: 10px" content="" render-fun="setValue" render-key="list.id">
                                    共<span render-html="list.ofCommentNums"></span> 条回复>>> </i>
                                <i class="fa fa-thumbs-o-up likeBtn" content="" render-fun="setValue" render-key="list.id"> <span render-html="list.commentLikers"></span> 赞</i>
                            </a>
                        </div>

                    </div>
                </div>

            </div>
        </div>

    </div>


</div>
</div>

<div class="operation">
    <button class="btn">加入旅行单</button>
    <button class="btn" id="commentBtn">点评</button>
</div>

</body>
</html>